import { NativeModules } from "react-native";
import { IBridge, LoginOption, ShareOptions } from "./IBridge";

const loginModule = NativeModules.UMverifyModule;
const colorThiefModule = NativeModules.RNColorThief;
const shareModule = NativeModules.UMShareModule;

class NativeBridge implements IBridge{
    login(option: LoginOption): void {
        loginModule.login((str)=>{
            let res = null;
            try {
                res = JSON.parse(str);
            } catch (error) {
                console.error(res);
            }
            option.onSuccess(res);
        },option.onFail);
    }
    
    getMainColor(src:string,quality?:number,ingoreWhite?:boolean){
        return colorThiefModule.getColor(src,quality,ingoreWhite);
    }

    shareBoard(options:ShareOptions){
        const { text,img,weburl,title,platforms = [0,1,2,3,4],success } = options;
        shareModule.shareboard(text,img,weburl,title,platforms,success);
    }

}

export default NativeBridge;